package com.ydd.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ydd.entity.SysRoleMenu;
import org.apache.ibatis.annotations.Mapper;
import com.ydd.vo.common.MenuIdAndPid;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;

import java.util.List;

import java.util.List;

/**
 * @Description TODO
 * @Author fang
 * @Date 2023-05-29 16:08
 */
@Mapper
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
    /**
     * 菜单删除-关联表role—menu删除关系
     * @param menuId
     */
    @Delete("delete from sys_role_menu where menu_id=#{menuId}")
    void deleteByMenuId(Integer menuId);

    /**
     * 根据
     * @return
     */
    @Select("select group_concat(menu_id) as role_menus from sys_role_menu where role_id=#{roleId}")
    String getRoleIdAndMenuId(String roleId);


    /**
     * 连表查询PID
     * @param id
     * @return
     */
    List<MenuIdAndPid> getPidByRoleId(String id);

    /**
     * 根据角色id删除菜单关联
     */
    @Delete("delete from sys_role_menu where role_id=#{role_id}")
    void deleteMenuByRoleId(String role_id);

    /**
     * 根据名字查询角色id
     * @param name
     * @return
     */
    @Select("select id from sys_role where name=#{name}")
    String getRoleIdByName(String name);

    /**
     * 角色修改关联表
     * @param menuids
     * @param id
     */
    void updateRoleMenu(@Param("menuids") List<String> menuids, String id);

    /**
     *根据角色id删除对应的菜单id
     * @param RoleId
     */
    @Delete("delete from sys_role_menu where role_id=#{RoleId}")
    void deleteMenuRoleById(String RoleId);


    /**
     * 恢复系统主要菜单
     */
    void addMenu();

    /**
     * 根据角色id获取菜单id集合
     * @param id
     * @return
     */
    @Select("select menu_id from sys_role_menu where role_id=#{id}")
    List<String> getMenuIdByRoleId(String id);
}
